package com.car.service.Impl;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.config.AlipayConfig;
import com.alipay.config.LahuoConfig;
import com.car.entity.Laorder;
import com.car.mapper.LaorderMapper;
import com.car.service.LaorderService;
@Service
public class LaorderServiceImpl implements LaorderService{
@Autowired
LaorderMapper laorder;
	@Override
	public int count(int userid) {
		// TODO Auto-generated method stub
		return laorder.count(userid);
	}
	@Override
	public int counts(int state, int userid) {
		// TODO Auto-generated method stub
		return laorder.counts(state, userid);
	}
	@Override
	public List<Laorder> selectlist(int state, int userid) {
		// TODO Auto-generated method stub
		return laorder.selectlist(state, userid);
	}

	public void ali(HttpServletResponse response, HttpServletRequest request, String orderId, Integer money)
			throws AlipayApiException, IOException {
		   response.setContentType("text/html;charset=utf-8");
		   
	        PrintWriter out = response.getWriter();
	        //获得初始化的AlipayClient
	        AlipayClient alipayClient = new DefaultAlipayClient(LahuoConfig.gatewayUrl, LahuoConfig.app_id, LahuoConfig.merchant_private_key, "json", LahuoConfig.charset, LahuoConfig.alipay_public_key, LahuoConfig.sign_type);
	        //设置请求参数
	        AlipayTradePagePayRequest aliPayRequest = new AlipayTradePagePayRequest();
	        aliPayRequest.setReturnUrl(LahuoConfig.return_url);
	        aliPayRequest.setNotifyUrl(LahuoConfig.notify_url);
	        //商户订单号，后台可以写一个工具类生成一个订单号，必填
	        String order_number = orderId;
	        //付款金额，从前台获取，必填
	        String total_amount = money.toString();
	        //订单名称，必填
	        String subject = new String("拉车订单");
	        aliPayRequest.setBizContent("{\"out_trade_no\":\"" + order_number + "\","
	                + "\"total_amount\":\"" + total_amount + "\","
	                + "\"subject\":\"" + subject + "\","
	                + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
	        //请求
	        String result = alipayClient.pageExecute(aliPayRequest).getBody();
	        //输出
	        out.println(result);//以下写自己的订单代码
	
		
	}
	@Override
	public int orderadd(Laorder laorders) {
		// TODO Auto-generated method stub
		return laorder.orderadd(laorders);
	}
	@Override
	public int stateupd(String orderid) {
		// TODO Auto-generated method stub
		return laorder.stateupd(orderid);
	}
	@Override
	public List<Laorder> selectall() {
		// TODO Auto-generated method stub
		return laorder.selectall();
	}
	@Override
	public List<Laorder> selectstate(int carid, int state) {
		// TODO Auto-generated method stub
		return laorder.selectstate(carid, state);
	}
	@Override
	public Laorder orderupdsel(int id) {
		// TODO Auto-generated method stub
		return laorder.orderupdsel(id);
	}
	@Override
	public int stateupd(int id) {
		// TODO Auto-generated method stub
		return laorder.stateupds(id);
	}
	

}
